Skip to content

feat: Propagating the otel context#1033

Merged
copybara-service[bot] merged 1 commit intomainfrom
test_881463869
Mar 17, 2026
Merged

feat: Propagating the otel context#1033
copybara-service[bot] merged 1 commit intomainfrom
test_881463869

Conversation

@copybara-service
Copy link

@copybara-service copybara-service bot commented Mar 13, 2026

feat: Propagating the otel context

This change ensures that the OpenTelemetry context is correctly propagated across asynchronous boundaries throughout the ADK, primarily within RxJava streams.

Key Changes

  • Context Propagation: Replaces manual Scope management (which often fails in reactive code) with .compose(Tracing.withContext(context)). This ensures the OTel context is preserved when work moves between different threads or schedulers.
  • Runner Refactoring:
    • Adds a top-level "invocation" span to runAsync and runLive calls.
    • Captures the context at entry points and propagates it through the internal execution flow (runAsyncImpl, runLiveImpl, runAgentWithFreshSession).
  • BaseLlmFlow & Functions: Updates preprocessing, postprocessing, and tool execution logic to maintain context. This ensures that spans created within tools or processors are correctly parented.
  • PluginManager: Ensures that plugin callbacks (like afterRunCallback and onEventCallback) execute within the captured context.
  • Testing: Adds several unit tests across BaseLlmFlowTest, FunctionsTest, PluginManagerTest, and RunnerTest that specifically verify context propagation using ContextKey and Schedulers.computation().

Files Modified

  • BaseLlmFlow.java, Functions.java, PluginManager.java, Runner.java: Core logic updates for context propagation.
  • LlmAgentTest.java, BaseLlmFlowTest.java, FunctionsTest.java, PluginManagerTest.java, RunnerTest.java: New tests for OTel integration.
  • BUILD files: Updated dependencies for OpenTelemetry APIs and SDK testing.

@copybara-service copybara-service bot force-pushed the test_881463869 branch 7 times, most recently from 9c612fa to 5f88fdf Compare March 16, 2026 20:02
@copybara-service copybara-service bot changed the title feat: Propogating the otel context feat: Propagating the otel context Mar 16, 2026
@copybara-service copybara-service bot force-pushed the test_881463869 branch 7 times, most recently from c41fa9c to 9c3d862 Compare March 17, 2026 13:54
This change ensures that the OpenTelemetry context is correctly propagated across asynchronous boundaries throughout the ADK, primarily within RxJava streams.

### Key Changes

*   **Context Propagation:** Replaces manual `Scope` management (which often fails in reactive code) with `.compose(Tracing.withContext(context))`. This ensures the OTel context is preserved when work moves between different threads or schedulers.
*   **`Runner` Refactoring:**
    *   Adds a top-level `"invocation"` span to `runAsync` and `runLive` calls.
    *   Captures the context at entry points and propagates it through the internal execution flow (`runAsyncImpl`, `runLiveImpl`, `runAgentWithFreshSession`).
*   **`BaseLlmFlow` & `Functions`:** Updates preprocessing, postprocessing, and tool execution logic to maintain context. This ensures that spans created within tools or processors are correctly parented.
*   **`PluginManager`:** Ensures that plugin callbacks (like `afterRunCallback` and `onEventCallback`) execute within the captured context.
*   **Testing:** Adds several unit tests across `BaseLlmFlowTest`, `FunctionsTest`, `PluginManagerTest`, and `RunnerTest` that specifically verify context propagation using `ContextKey` and `Schedulers.computation()`.

### Files Modified
*   **`BaseLlmFlow.java`**, **`Functions.java`**, **`PluginManager.java`**, **`Runner.java`**: Core logic updates for context propagation.
*   **`LlmAgentTest.java`**, **`BaseLlmFlowTest.java`**, **`FunctionsTest.java`**, **`PluginManagerTest.java`**, **`RunnerTest.java`**: New tests for OTel integration.
*   **`BUILD` files**: Updated dependencies for OpenTelemetry APIs and SDK testing.

PiperOrigin-RevId: 884998997
@copybara-service copybara-service bot merged commit 8556d4a into main Mar 17, 2026
@copybara-service copybara-service bot deleted the test_881463869 branch March 17, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant